<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
	<link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div style="text-align: center;">
	<h2>采购进货</h2>
</div>
<div class="layui-form" lay-filter="sbmitPurchase">
	<!-- 功能栏 -->
	<form class="layui-form" style="height: 100px;">
		<div style="color: red; width: 100%;">
					<span style="float: right; padding-right: 50px;">订单号：
						<input type="text" readonly="" name="purStoId"
							   style="border:none;color:red;background:#f2f2f2 " />
					</span>
		</div>
		<div class="layui-col-md12">
			<div class="layui-panel" style="padding-top: 20px;margin-top: 5px;">
				<div class="layui-form-item layui-font-black ">
					<div class="layui-inline">
						<label class="layui-form-label">供货商：</label>
						<div class="layui-input-inline">
							<input type="text" class="layui-input"  lay-verify="required"  name="supId" id="supplierName"
								   placeholder="请选择">
						</div>
						<script type="text/html" id="customerOperater">
							<div class="layui-btn-container">
								<a class="layui-btn layui-btn-sm" lay-event="addSupplier" id="addSupplier">新增供货商</a>
							</div>
						</script>
						<script type="text/html" id="customerOperaterIn">
							<div class="layui-btn-container">
								<a class="layui-btn layui-btn-sm" lay-event="editSupplier" id="editSupplier">修改</a>
							</div>
						</script>

					</div>
					<div class="layui-inline">
						<label class="layui-form-label">收货仓库：</label>
						<div class="layui-input-inline">
							<select id="interestDepot"  lay-verify="required" lay-filter="interestDepot" name="depotId">
								<option value="">请选择</option>
							</select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">进货时间：</label>
						<div class="layui-input-inline">
							<input type="text" class="layui-input"  lay-verify="required" name="purStoDate" id="test19"
								   placeholder="yyyy-MM-dd">
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
	<!-- 表头功能 -->
	<script type="text/html" id="toolbarDemo">
		<div class="layui-btn-container">
			<button class="layui-btn layui-btn-sm" lay-event="laocomInsert">采购进货</button>
		</div>
	</script>
	<!-- 表格 -->
	<table class="layui-table" id="currentTableId" lay-filter="currentTableId"></table>
	<form class="layui-form">
		<div class="layui-panel" style="padding-top: 20px;margin-top: 5px;">
			<div class="layui-form-item layui-font-black ">
				<label class="layui-form-label">应付金额:</label>
				<div class="layui-input-inline" style="width: 100px;">
					<input type="text" name="purStoPayable" lay-verify="required"  placeholder="请输入"
						   autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label">实付金额:</label>
				<div class="layui-input-inline"   style="width: 100px;">
					<input type="text" lay-verify="required" name="purStoOutof" placeholder="请输入"
						   autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label">经办人:</label>
				<div class="layui-input-inline"  style="width: 100px;">
					<select id="employeeInsert" lay-verify="required"  lay-filter="employeeInsert" name="empId">
						<option value="">请选择</option>
					</select>
				</div>
				<label class="layui-form-label">原始单号:</label>
				<div class="layui-input-inline">
					<input type="text" name="purStoOriginalNum" placeholder="请输入" autocomplete="off"
						   class="layui-input">
				</div>
			</div>
			<div class="layui-form-item layui-font-black ">
				<label class="layui-form-label">备注:</label>
				<div class="layui-input-inline" style="width: 320px;">
					<input type="text" name="purStoCommment" placeholder="请输入" autocomplete="off"
						   class="layui-input">
				</div>
				<label class="layui-form-label">计划时间:</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" name="purStoPreDate" id="test20"
						   placeholder="yyyy-MM-dd">
				</div>
				<button button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit
						lay-filter="insertPurchase" style="margin-left: 50px;">保存</button>
				<button type="button" class="layui-btn layui-btn-sm layui-btn-normal"
						style="margin-left: 20px;">退出</button>
			</div>
		</div>
	</form>
</div>
<!-- 弹出层添加老商品信息 -->
<div id="insertCommodityInfo" style="display: none;">
	<div class="layui-row-col layui-space1">
		<div class="layui-col-md6">
			<div class="layui-form-item layui-font-black" style="padding-top: 5px;">
				<label class="layui-form-label" style="width: 200px;">输入商品编号或商品名称查询:</label>
				<div class="layui-input-inline" style="width: 130px;">
					<input type="text" name="productInformation" lay-verify="required" placeholder="请输入"
						   autocomplete="off" class="layui-input">
				</div>
				<button type="button" class="layui-btn " id="inertProduct">加入所选商品</button>
			</div>
			<div class="layui-tab layui-tab-card ">
				<ul class="layui-tab-title">
					<li class="layui-this">商品清单</li>
					<li>商品列表</li>
					<li>最近进货</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show" id="tabijk">
						<script type="text/html" id="proAdd">
							<div class="layui-btn-container">
								<button class="layui-btn layui-btn-sm" lay-event="xincomInsert">新商品添加</button>
							</div>
						</script>
						<!-- 表格 -->
						<table class="layui-hide" id="inventoryId" lay-filter="inventoryId"></table>
					</div>

					<div class="layui-tab-item layui-row-col">
						<div id="product_list" class="layui-col-md4" style="height:366px; overflow:auto;">

						</div>
						<table class="layui-hide layui-col-md8" id="proList" lay-filter="proList"></table>
					</div>
					<div class="layui-tab-item">
						<table class="layui-hide layui-col-md8" id="recentStock" lay-filter="recentStock">
						</table>
					</div>
				</div>
			</div>
		</div>
		<div class="layui-col-md6">
			<span style="font-weight: bold;">所选商品</span><br />
			<!-- 表格 -->
			<script type="text/html" id="selectedProdut">
				<div class="layui-btn-container">
					<button class="layui-btn layui-btn-sm" lay-event="delProduts">删除</button>
					<button class="layui-btn layui-btn-sm" lay-event="insertProduts">确定</button>
				</div>
			</script>
			<table class="layui-hide" id="chooseProductsId" lay-filter="chooseProductsId"
				   style="overflow:auto;"></table>
		</div>
	</div>
</div>




<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    //保存表格数据
    var tableContents = [];

    //保存订单详情表格数据
    var currentTableList = [];

    window.purchaseDetailsInfo = '';
    var ifproductInfo = 'leftProduct';
    layui.use(['form', 'table', 'layer', 'tree', 'tableSelect'], function() {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            tableSelect = layui.tableSelect,
            layer = layui.layer,
            tree = layui.tree;
        var laydate = layui.laydate;

        //时间控件
        laydate.render({
            elem: '#test19',
            value: new Date(),
            isInitValue: true,
        });
        laydate.render({
            elem: '#test20',
            isInitValue: true
        });
		//判断表格是否为空

		var tablecurrent = false;
        //订单信息表格表头
        table.render({
            elem: '#currentTableId',
            data: currentTableList,
            toolbar: '#toolbarDemo',
            totalRow:true,
            cols: [
                [{
                    type: "checkbox",
                    width: 30
                },
                    {
                        field: 'proId',
                        width: 120,
                        title: '商品编号',
                        sort: true
                    },
                    {
                        field: 'proName',
                        width: 120,
                        title: '商品名称'
                    },
                    {
                        field: 'purStoDescUnit',
                        width: 80,
                        title: '单位',
                        sort: true
                    },
                    {
                        field: 'proSize',
                        width: 120,
                        title: '产品规格'
                    },
                    {
                        field: 'proPostil',
                        title: '批准文号',
                        width: 120
                    },
                    {
                        field: 'proBatchNum',
                        width: 170,
                        title: '产品批号',
                        sort: true
                    },
                    {
                        field: 'inveDescStartDate',
                        width: 120,
                        title: '生产日期',
                        sort: true
                    },
                    {
                        field: 'inveDescValidityDate',
                        width: 120,
                        title: '有效期至'
                    },
                    {
                        field: 'proBid',
                        width: 100,
                        title: '单价',
                        sort: true
                    },
                    {
                        field: 'purStoDescNum',
                        width: 120,
                        title: '数量',
                        totalRow:true
                    },
                    {
                        field: 'totalMoney',
                        width: 120,
                        title: '总金额',
                        totalRow:true
                    },
                    {
                        field: 'manufacturerName',
                        width: 120,
                        title: '生产厂商'
                    },
                    {
                        field: 'proSalePrice',
                        width: 80,
                        title: '预售价',
                        totalRow:true
                    },
                    {
                        field: 'totalPrice',
                        width: 120,
                        title: '售价总额',
                        templet: function(d) {
                            return d.proSalePrice * d.proBid
                            totalRow:true
                        }
                    }
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: false,
            skin: 'line',
			done:function (obj) {
                $("input[name=purStoPayable]").val($('#currentTableId~div .layui-table-total td[data-field=totalMoney] div').html());
                if(0<=obj.data.length){
                    tablecurrent=true
                    console.log(tablecurrent)
				}
            }
        });
        //所选表格表头
        table.render({
            elem: '#chooseProductsId',
            height: 497,
            toolbar: '#selectedProdut',
            data: tableContents,
			totalRow:true,
            cols: [
                [{
                    type: "checkbox",
                    width: 50
                },
                    {
                        field: 'proName',
                        width: 150,
                        title: '商品名称',
                        sort: true
                    },
                    {
                        field: 'unitName',
                        width: 60,
                        title: '单位'
                    },
                    {
                        field: 'proBid',
                        width: 80,
                        title: '进价',
                        sort: true,

                    },
                    {
                        field: 'purStoDescNum',
                        width: 120,
                        title: '数量',
                        totalRow:true
                    },
                    {
                        field: 'totalMoney',
                        title: '总金额',
                        minWidth: 120,
                        totalRow:true
                    },
                    {
                        field: 'inveDescBatchNum',
                        width: 150,
                        title: '产品批号',
                        sort: true
                    },
                    {
                        field: 'inveDescStartDate',
                        width: 150,
                        title: '生产日期',
                        sort: true
                    },
                    {
                        field: 'inveDescValidityDate',
                        width: 150,
                        title: '有效期'
                    },
                    {
                        field: 'inveDescComment',
                        width: 135,
                        title: '备注',
                        sort: true
                    }
                ]
            ],

            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: false,
            skin: 'line',

        });

        //商品列表
        table.render({
            elem: '#proList',
            data: [],
            height: 372,
            cols: [
                [{
                    field: 'proId',
                    width: 120,
                    title: '商品编号',
                    sort: true
                },
                    {
                        field: 'proName',
                        width: 120,
                        title: '商品名称'
                    },
                    {
                        field: 'unitName',
                        width: 120,
                        title: '单位',
                        sort: true,
                        templet: function(obj) {
                            if (null == obj.productUnit) {
                                return '';
                            }
                            return obj.productUnit.unitName;
                        }
                    },
                    {
                        field: 'proBid',
                        title: '参考进价',
                        width: 140
                    },
                    {
                        field: 'proSize',
                        width: 120,
                        title: '规格'
                    },

                    {
                        field: 'inveDescInventoryNum',
                        title: '库存数量',
                        width: 140,
                        templet: function(obj) {
                            if (null == obj.inventoryDesc) {
                                return 0;
                            }
                            return obj.inventoryDesc.inveDescInventoryNum;
                        }
                    },
                    {
                        field: 'manufacturerName',
                        width: 140,
                        title: '生产厂商',
                        templet: function(obj) {
                            if (null == obj.manufactureridInfo) {
                                return '';
                            }
                            return obj.manufactureridInfo.manufacturerName;
                        }
                    },
                ]
            ],
            page: false,
            skin: 'line',
            done: function(res, curr, count) {
                $('.layui-table-view[lay-id="proList"]')
                    .children('.layui-table-box')
                    .children('.layui-table-body')
                    .find('table tbody tr[data-index="0"]').click();


            }
        });
        //最近进货
        table.render({
            elem: '#recentStock',
            height: 372,
            url: '/searchRecentStock',
            cols: [
                [
                    {
                        field: 'proId',
                        width: 140,
                        title: '商品编号',
                        sort: true
                    },

                    {
                        field: 'proName',
                        width: 140,
                        title: '商品名称'
                    },

                    {
                        field: 'purStoDescNum',
                        width: 120,
                        title: '数量',
                        sort: true
                    },

                    {
                        field: 'purStoDescPrice',
                        width: 120,
                        title: '单价'
                    },

                    {
                        field: 'purStoDescUnit',
                        title: '单位',
                        width: 100
                    },

                    {
                        field: 'purchaseSize',
                        width: 120,
                        title: '规格',
                        sort: true
                    },
                    {
                        field: 'purStoDate',
                        width: 160,
                        title: '进货日期',templet:"<div>{{layui.util.toDateString(d.purchaseStock.purStoDate, 'yyyy-MM-dd')}}</div>"

                    }

                ]
            ],

            limits: [10, 15, 20, 25, 50, 100],

            limit: 15,

            page: false,

            skin: 'line'

        });

        //商品清单表格表头
        var productInformation = $("input[name=productInformation]").val();
        table.render({
            elem: '#inventoryId',
            url: '/searchProInfo?proName=' + productInformation,
            height: 372,
            toolbar: '#proAdd',
            cols: [
                [{
                    field: 'proId',
                    width: 120,
                    title: '商品编号',
                    sort: true
                },
                    {
                        field: 'proName',
                        width: 120,
                        title: '商品名称'
                    },
                    {
                        field: 'unitName',
                        width: 120,
                        title: '单位',
                        sort: true,
                        templet: function(obj) {
                            if (null == obj.productUnit) {
                                return '';
                            }
                            return obj.productUnit.unitName;
                        }
                    },
                    {
                        field: 'proSize',
                        width: 120,
                        title: '规格'
                    },
                    {
                        field: 'proBid',
                        title: '参考进价',
                        width: 140
                    },
                    {
                        field: 'inveDescInventoryNum',
                        title: '库存数量',
                        width: 140,
                        templet: function(obj) {
                            if (null == obj.inventoryDesc) {
                                return 0;
                            }
                            return obj.inventoryDesc.inveDescInventoryNum;
                        }
                    },
                    {
                        field: 'manufacturerName',
                        width: 140,
                        title: '生产厂商',
                        templet: function(obj) {
                            if (null == obj.manufactureridInfo) {
                                return '';
                            }
                            return obj.manufactureridInfo.manufacturerName;
                        }
                    },
                    {
                        field: 'proComment',
                        width: 120,
                        title: '备注',
                        hide: true
                    }
                ]
            ],
            page: false,
            skin: 'line',
            done: function(res, curr, count) {
                $('.layui-table-view[lay-id="inventoryId"]')
                    .children('.layui-table-box')
                    .children('.layui-table-body')
                    .find('table tbody tr[data-index="0"]').click();
                purchaseDetailsInfo = JSON.stringify(res.data[0]);
            }
        });

        //按键被松开时触发
        $("input[name=productInformation]").on('keyup', function() {

            var ret = /^[.{0}a-zA-Z0-9-\u4eoo-\u9fa5]+$/;
            productInformation = $(this).val();

            if (ret.test(productInformation)) {
                layui.table.reload('inventoryId', {
                    url: '/searchProInfo?proName=' + productInformation,
                })
            } else {
                productInformation = '';
                $(this).val(productInformation);

                layui.table.reload('inventoryId', {
                    url: '/searchProInfo?proName=' + productInformation,
                })

            }
        });
        $("#inertProduct").on('click', function() {
            //调用修改商品信息子页面
            updateCommodity();

        })

        //所选表格双击事件
        table.on('rowDouble(chooseProductsId)', function(obj) {
            //获取父页面表格数据
            var row = obj.data;

            //通过window.purchaseDetailsInfo对象将父页面数据传递给子页面
            purchaseDetailsInfo = JSON.stringify(row);
            console.log(JSON.stringify(row))
            //判断传递的页面
            ifproductInfo = 'rightProduct';
            /*调用修改商品弹出层*/
            updateCommodity();
        })


        //绑定点击事件
        table.on('toolbar(currentTableId)', function(obj) {
            switch (obj.event) {
                case "laocomInsert":
                    insertCommodityInfo();
                    break;
            }

        })
        //添加商品弹出层
        function insertCommodityInfo() {
            layer.open({
                type: 1,
                title: '<h2 style="font-weight: bold;">添加商品(采购进货)<h2>',
                scrollbar: false,
                area: ['100%', '100%'],
                content: $('#insertCommodityInfo')
            });
        }
        //主页面点击行事件
        table.on('row(currentTableId)', function(obj) {
            obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
        });
        //主页面双击行事件
        table.on('rowDouble(currentTableId)', function(obj) {
            var data = obj.data;
            //获取table表格数据传递给子页面
            purchaseDetailsInfo = JSON.stringify(data);
            //调用修改商品信息子页面
            //判断传递的页面
            ifproductInfo = 'centerProduct';
            updateCommodity();
        });
        //商品清单绑定点击事件
        table.on('toolbar(inventoryId)', function(obj) {
            switch (obj.event) {
                case "xincomInsert":
                    insertNewCommodityInfo();
                    break;
            }
        })
        //商品清单绑定单击事件
        table.on('row(inventoryId)', function(obj) {
            obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');

            purchaseDetailsInfo = JSON.stringify(obj.data);
        });
        //弹出层老商品  商品清单双击行事件
        table.on('rowDouble(inventoryId)', function(obj) {
            //获取父页面表格数据
            var row = obj.data;
            //通过window.purchaseDetailsInfo对象将父页面数据传递给子页面
            purchaseDetailsInfo = JSON.stringify(row);
            //判断传递的页面
            ifproductInfo = 'leftProduct';
            /*调用修改商品弹出层*/
            updateCommodity();
        })
        //商品列表双击行事件
        table.on('rowDouble(proList)', function(obj) {
            //获取父页面表格数据
            var row = obj.data;
            //通过window.purchaseDetailsInfo对象将父页面数据传递给子页面
            purchaseDetailsInfo = JSON.stringify(row);
            //判断传递的页面
            ifproductInfo = 'leftProduct';
            /*调用修改商品弹出层*/
            updateCommodity();
        })


        //弹出层老商品  最近进货双击行事件
        table.on('rowDouble(recentStock)', function(obj) {
            //获取父页面表格数据
            obj.data.purStoDate= layui.util.toDateString(obj.data.purStoDate, 'yyyy-MM-dd');
            obj.data.purStoDescStartDate=  layui.util.toDateString(obj.data.purStoDescStartDate, 'yyyy-MM-dd');
            obj.data.purchaseProValidityDate= layui.util.toDateString(obj.data.purchaseProValidityDate, 'yyyy-MM-dd');

            // //通过window.purchaseDetailsInfo对象将父页面数据传递给子页面
            purchaseDetailsInfo = JSON.stringify(obj.data);
			console.log(purchaseDetailsInfo)
            //判断传递的页面
             ifproductInfo = 'leftrecentStock';
            /*调用修改商品弹出层*/
            updateCommodity();
        })



        //供应商Id
        var supId = '';
        // 供货商信息下拉选项
        tableSelect.render({
            elem: '#supplierName',
            id: 'supperlier',
            checkedKey: 'id',
            table: {
                url: '/sraechSupplierInfo',
                cellMinWidth: 100, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                toolbar: '#customerOperater',
                cols: [
                    [{
                        type: 'radio'
                    },
                        {
                            field: 'supId',
                            title: '编号'
                        },
                        {
                            field: 'supName',
                            title: '供货商名称'
                        },
                        {
                            field: 'supPeople',
                            title: '联系人'
                        },
                        {
                            field: 'supPhone',
                            title: '联系电话'
                        },
                        {
                            field: 'supAddress',
                            title: '联系地址'
                        },
                        {
                            field: 'supType',
                            title: '供货商类型'
                        },
                        {
                            field: 'supRegion',
                            title: '供货商地区'
                        },
                        {
                            title: '操作按钮',
                            toolbar: '#customerOperaterIn'
                        }
                    ]
                ]
            },
            done: function(elem, data) {
                var NEWJSON = []
                layui.each(data.data, function(index, item) {
                    NEWJSON.push(item.supName)
                    supId = item.supId;
                })
                elem.val(NEWJSON.join(","));
            }

        });
        // 供货商名称下拉选项（新增供货商信息）【监听头部工具栏事件】
        table.on('toolbar(supperlier)', function(obj) {
            switch (obj.event) {
                case "addSupplier":
                    var index = layer.open({
                        title: '增加供货商',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '90%'],
                        content: 'purchase_addSupomer.html',
                        zIndex: 66666667
                    });
                    break;
            }
        });
        // 供货商名称下拉选项（编辑供货商信息）【监听行工具事件】
        table.on('tool(supperlier)', function(obj) {
            switch (obj.event) {
                case "editSupplier":
                    var supplierInfoObj = obj.data; //JSON.stringify(data)
                    //JSON格式对象 --> String对象
                    window.supplierInfo = JSON.stringify(supplierInfoObj);
                    var index = layer.open({
                        title: '修改供货商',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '90%'],
                        content: 'purchase_editSupplier.html',
                        zIndex: 66666667
                    });
                    break;
            }
        });
        //商品列表分类树形控件
        $.ajax({
            dataType: 'json',
            url: "/searchProdutType",
            success: function(msg) {
                tree.render({
                    elem: '#product_list' //绑定元素
                    ,
                    data: msg.data,
                    click: function(obj) { //根据输入商品信息 动态查询商品
                        if (obj.data.children == null) {
                            var proTypeId = obj.data.id;

                            table.reload('proList', {
                                url: '/searchProInfoClassify?proTypeId=' +
                                proTypeId,
                            })
                        }
                    }
                })
            }
        });

        //弹出层新商品添加函数
        function insertNewCommodityInfo() {
            layer.open({
                type: 2,
                title: '<h2 style="font-weight: bold;">增加商品<h2>',
                scrollbar: false, //屏蔽浏览器滚动条
                area: ['60%', '100%'],
                content: 'productInsert.html'
            });
        }
        /*修改商品的函数*/
        function updateCommodity() {
            layer.open({
                type: 2,
                title: '<h2 style="color: #000000;font-weight: bold;">商品信息(采购进货)<h2>',
                scrollbar: false,
                area: ['80%', '90%'],
                /*宽高*/
                /*btn: ['确定','退出'],
                btnAlign: 'c',*/
                content: 'updateMerchandise.html'
            });
        }


        //创建一个集合用于存储选中行的下标
        var trIndexList = [];
        //监听表格复选框选择
        table.on('checkbox(chooseProductsId)', function(obj) {
            //获取选中行的下标(从零开始)
            var trIndex = obj.tr.attr('data-index');
            //获取是否为全选
            var isAll = table.checkStatus('chooseProductsId').isAll;

            //判断是全选则添加所有所选商品
            if (isAll) {
                trIndexList = [];
                for (var i = 0, len = tableContents.length; i < len; i++) {
                    trIndexList.push(i);
                }
            } else if (undefined == trIndex) {
                //判断是反选清空所有所选商品
                trIndexList = [];
            } else {
                //判断复选框的选中状态，进行增加 | 删除
                if (obj.checked) {
                    //添加选中的下标至数组末尾
                    trIndexList.push(trIndex);
                } else {
                    //从数组中删除取消的一个元素
                    trIndexList.splice($.inArray(trIndex, trIndexList), 1);
                }
            }
        });

        //监听所选列表提交事件
        table.on('toolbar(chooseProductsId)', function(obj) {
            //判断数据是追加还是修改
            switch (obj.event) {
                case 'insertProduts':
                    for (var i = 0; i < tableContents.length; i++) {
                        var currentFlag = true;
                        var tableContentObj = tableContents[i];
                                for (var j = 0; j < currentTableList.length; j++) {
                                    if (currentTableList[j].proId == tableContentObj.proId &&
                                        currentTableList[j].inveDescBatchNum == tableContentObj.inveDescBatchNum ){//&& currentTableList[j].proBid == tableContentObj.proBid
                                        currentTableList[j].purStoDescNum = parseInt(currentTableList[j]
                                                .purStoDescNum)+
                                            parseInt(tableContentObj.purStoDescNum);
                                        currentFlag = false;
                                        break;
                                    }
                                    currentTableList.totalMoney = currentTableList[j].purStoDescNum *
                                        currentTableList.proBid;
                                }
								if (currentFlag) {
									currentTableList.push(tableContentObj)
								}
                    }

                    table.reload('currentTableId', {
                        data: currentTableList,
                        done:function (obj) {
                            if(0<=obj.data.length){
                                tablecurrent=false
                            }
                            $("input[name=purStoPayable]").val($('#currentTableId~div .layui-table-total td[data-field=totalMoney] div').html());
                        }
                    })

                    tableContents = [];
                    layui.table.reload('chooseProductsId', {
                        //填充data属性
                        data: tableContents,
                        done:function (obj) {


                        }
                    })
                    //关闭弹窗
                    layer.closeAll();
                    break;
                case 'delProduts':
                    //升序排列
                    trIndexList = trIndexList.sort();
                    if (null != trIndexList && 0 < trIndexList.length) {
                        layer.open({
                            content: '确认要删除选中的数据么',
                            yes: function(index, layero) {
                                //循环遍历选中的行下标
                                for (var i = 0, len = trIndexList.length; i < len; i++) {
                                    //删除选中的数据行
                                    tableContents.splice(trIndexList[i], 1);
                                    //判断选中的行数大于一条且不是最后一条时，改变后一条的位置的值
                                    if (1 < trIndexList.length && i != trIndexList.length -
                                        1) {
                                        //后一条前移(i+1)位
                                        trIndexList[i + 1] = trIndexList[i + 1] - 1 - i;
                                    }
                                }
                                //重载数据表格
                                table.reload('chooseProductsId', {
                                    data: tableContents
                                });
                                //清空保存下标位置的数组
                                trIndexList = [];

                                //手动关闭弹窗
                                layer.close(index);
                            }
                        });
                    } else {
                        layer.msg('没有选择待删除的数据！', {
                            time: 500
                        });
                    }


                    break;

            };
        });



        //收货仓库
        $.ajax({
            url: '/searchDepotInfo',
            dataType: 'json',
            type: 'get',
            success: function(data) {
                $.each(data, function(index, item) {
                    // 下拉菜单里添加元素
                    $('#interestDepot').append(new Option(item.depotName, item.depotId));
                });
                //重新渲染 固定写法
                layui.form.render("select");
            }
        });

        //经手人
        $.ajax({
            url: '/searchEmployeeInfo',
            dataType: 'json',
            type: 'get',
            success: function(data) {

                $.each(data, function(index, item) {
                    // 下拉菜单里添加元素
                    $('#employeeInsert').append(new Option(item.empName, item.empId));
                });
                //重新渲染 固定写法
                layui.form.render("select");
            }
        });

        function purchaseOrderId() {
            var date = new Date();
            var y = date.getFullYear(); //获取当前年
            var month = date.getMonth() + 1; //获取当前月
            var d = date.getDate(); //获取当前日
            var h = date.getHours(); //获取当前小时数(0-23)
            var m = date.getMinutes(); //获取当前分钟数(0-59)
            var s = date.getSeconds(); //获取当前秒
            if (month < 10) {
                month = '0' + month;
            }
            if (s  < 10) {
                s  = '0' + month;
            }
            if (m < 10) {
                m  = '0' + month;
            }
            return "CG" + y + month + d + h + m + s;
        }

        //采购订单编号
        var inputPurchaseOrderId = $('input[name=purStoId]');
        inputPurchaseOrderId.val(purchaseOrderId());
        //表单提交按钮
        form.on('submit(insertPurchase)', function(data) {
            //采购订单表数据
            var purchaseStock = form.val("sbmitPurchase");
            purchaseStock.supId = supId;

            purchaseStock = JSON.stringify(purchaseStock);

            var purchaseStockDesc = [];

            for (var i = 0, len = currentTableList.length; i < len; i++) {
                var currentTableListObj = currentTableList[i];
                purchaseStockDesc.push({
                    "purStoDescId": (inputPurchaseOrderId.val() + i),
                    "purStoId": inputPurchaseOrderId.val(),
                    "proId": currentTableListObj.proId,
                    "proName": currentTableListObj.proName,
                    "purStoDescPrice": currentTableListObj.proBid,
                    "proBatchNum": currentTableListObj.inveDescBatchNum,
                    "purStoDescNum": currentTableListObj.purStoDescNum,
                    "purStoDescStartDate": currentTableListObj.inveDescStartDate,
                    "purchaseProValidityDate": currentTableListObj.inveDescValidityDate,
                    "purStoDescUnit": currentTableListObj.unitName,
                    "purStoDescManufacturer": currentTableListObj.manufacturerName,
                    "purchaseSize": currentTableListObj.proSize,
                    "purPostil": currentTableListObj.proPostil
                })
            }



                if(tablecurrent==true){
                    layer.msg("您尚未加入商品", {
                        time: 800
                    });
                    return false;
                }else {
                //转成JSON字符串格式后去除 '[' 与 ']'
                purchaseStockDesc = JSON.stringify(purchaseStockDesc).replace('[', '').replace(']', '');
                //局部刷新进行操作，跳转页面
                $.ajax({
                    url: "/updatePurchaseDesc/" + purchaseStock + "/" + purchaseStockDesc,
                    type: 'get',
                    success: function(obj) {
                        if (JSON.parse(obj)) {
                            layer.msg('新增销售信息成功！', {
                                time: 300
                            }, function() {
                                location.href = 'purchasingAgent.html';
                            });
                        } else {
                            layer.msg('新增销售信息失败！', {
                                time: 300
                            })
                        }
                    }
                });
                }



        });

    });
</script>
</body>
</html>
